class Solution {
public:
    int minimumSum(vector<int>& nums) {
        int n = nums.size();
        vector<int>l(n, 1e9), r(n, 1e9);
        for (int i = 1; i < n; i++) {
            l[i] = min(l[i - 1], nums[i - 1]);
            cout << l[i] << " ";
        }
        cout << endl;
        for (int i = n - 2; i >= 0; i--) {
            r[i] = min(r[i + 1], nums[i + 1]);
            cout << r[i] << " ";
        }
        cout << endl;
        int ma = 1e9;
        for (int i = 1; i <= n - 2; i++) {
            //ma=min(ma,l[i]+r[i]+nums[i]);
            cout << "i==" << i << "  l[i]==" << l[i] << "  r[i]==" << r[i] << endl;
            if (l[i] < nums[i] && r[i] < nums[i])ma = min(ma, l[i] + r[i] + nums[i]);
        }
        return ma == 1e9 ? -1 : ma;
    }
};